Skip to content

Free the model when the backend sends UnloadModel - #36

Merged
jondeandres merged 1 commit into
mainfrom
handle-unload-model
Nov 16, 2026
Merged

jondeandres merged 1 commit into
mainfrom
handle-unload-model

Conversation

@jondeandres

Copy link
Copy Markdown
Contributor

Problem

The backend sends UnloadModel when no model the organization permits fits the node, for example when it disables the only model. ServerAction::Unload only logged "not handled by this build". So the model stayed loaded and the app kept showing Ready, while the backend had closed the node's serving row and counted it as serving nothing. The node and the platform disagreed.

Change

  • New reload::unload() (src-tauri/src/reload.rs). It lets in-flight generations finish, cancelling any that outlast the drain timeout, then frees the model and accepts work again. It returns whether a model was loaded.
  • ServerAction::Unload (src-tauri/src/grpc_client.rs) now spawns handle_unload_model. That holds model_switch, so an unload cannot land in the middle of a LoadModel switch. It then calls reload::unload, sets ModelStatus::NoModel and logs the outcome.

No new message goes to the backend: it has already closed the rows. When the node is assigned a model again, a normal LoadModel follows.

Tests

  • unload_frees_the_model_after_in_flight_generations_finish: the model stays loaded until the in-flight generation finishes. New work is refused while draining and accepted again afterwards.
  • unload_with_nothing_loaded_is_a_no_op

Local runs: cargo test --workspace --all-targets, cargo clippy --workspace -- -D warnings and cargo fmt --check all pass. There are no frontend changes, so Playwright was not run.

Not covered by tests: whether the UI shows the no-model state, and whether memory is freed on a real node after an unload. Worth a manual check on a release build.

Related

The backend half is nodea-sh/nodea#336: the scheduler now gives an emptied node a model again when one is re-enabled.

The backend sends UnloadModel when no model the organization permits
fits the node - e.g. it disabled the only one. The client only logged
it, so the model stayed resident and the app showed Ready while the
backend counted the node as serving nothing.

reload::unload drains in-flight generations, frees the model and
resumes accepting; the handler holds model_switch so an unload cannot
land mid-switch, and sets the status to NoModel.
@jondeandres
jondeandres merged commit 4d54027 into main Nov 16, 2026
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant